package com.ruicar.afs.cloud.manage.grace.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.manage.grace.condition.AreaCondition;
import com.ruicar.afs.cloud.parameter.commom.entity.TsysAddressParam;
import com.ruicar.afs.cloud.parameter.commom.service.TsysAddressParamService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author chuke
 * @create 2020/8/8 17:17
 */
@Slf4j
@RestController
@RequestMapping("/areaGrace")
@AllArgsConstructor
public class AreaGraceController {
    private final TsysAddressParamService tsysAddressParamService;


    @ApiOperation("根据地址查询编码")
    @PostMapping(value = "/findAreaCode")
    public IResponse findAreaCode(@RequestBody AreaCondition condition){
        TsysAddressParam cityInfo = tsysAddressParamService.getOne(Wrappers.<TsysAddressParam>lambdaQuery()
                .eq(TsysAddressParam::getLabel, condition.getLicensedAreaName()));
        return new IResponse().setData(cityInfo);
    }

    @ApiOperation("获取地区名称列表")
    @PostMapping(value = "/findAddressList")
    public IResponse findAddressList(){
        QueryWrapper<TsysAddressParam> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("label","value");
        List<TsysAddressParam> cityInfos = tsysAddressParamService.list(queryWrapper);
        return new IResponse().setData(cityInfos);
    }




}
